home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Interactive 7
/
PC World Interactive 7.iso
/
program
/
pasprog.EXE
/
OLINK.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-04-22
|
4KB
|
149 lines
unit olink;
interface
type
pLink = ^aLink;
aLink = object
prnt : pLink;
prev : pLink;
next : pLink;
head : pLink;
tail : pLink;
constructor create;
destructor destroy;virtual;
function Add(link:pLink):boolean;
function Del(link:pLink):boolean;
function Ins(link:pLink;after:pLink):boolean;
function MakeTop(child:pLink):boolean;
function MakeBot(child:pLink):boolean;
end;
function GetGlobalNext(link:pLink):pLink;
function GetGlobalPrev(link:pLink):pLink;
implementation
constructor aLink.create;
begin
prnt:=nil; prev:=nil; next:=nil; head:=nil; tail:=nil;
end;
function aLink.Add(link:pLink):boolean;
begin
Add:=false;
if ( (link=nil) or (link^.prnt<>nil) ) then exit;
if (head=nil)
then begin head:=link; link^.prev:=nil; end
else begin tail^.next:=link; link^.prev:=tail; end;
link^.next:=nil;
link^.prnt:=@self;
tail:=link;
Add:=true;
end;
function aLink.Del(link:pLink):boolean;
var
search : plink;
begin
Del:=false;
search:=head;
while ( (search<>link) and (search<>nil) ) do search:=search^.next;
if (search=nil) then exit;
if(link^.next<>nil)
then link^.next^.prev:=link^.prev
else tail:=link^.prev;
if(link^.prev<>nil)
then link^.prev^.next:=link^.next
else head:=link^.next;
link^.next:=nil;
link^.prev:=nil;
link^.prnt:=nil;
Del:=true;
end;
function aLink.Ins(link:pLink;after:pLink):boolean;
var
search : plink;
begin
Ins:=false;
if ( (link=nil) or (link^.prnt<>nil)) then exit;
if (after=nil)
then begin
if (head=nil) then begin
tail:=link;
end
else begin
head^.prev:=link;
end;
link^.next:=head;
head:=link;
end
else begin
search:=head;
while ( (search<>after) and (search<>nil) ) do search:=search^.next;
if (search=nil) then exit;
if (after^.next=nil) then tail:=link
else after^.next^.prev:=link;
link^.next:=after^.next;
after^.next:=link;
end;
link^.prnt:=@self;
link^.prev:=after;
Ins:=true;
end;
function GetGlobalNext(link:pLink):pLink;
var
search : plink;
begin
if link^.head<>nil
then GetGlobalNext:=link^.head
else if link^.next<>nil
then GetGlobalNext:=link^.next
else begin
search:=link^.prnt;
while (search<>nil) and (search^.next=nil)
do search:=search^.prnt;
if search=nil
then GetGlobalNext:=nil
else GetGlobalNext:=search^.next;
end;
end;
function GetGlobalPrev(link:pLink):pLink;
var
search : plink;
begin
if link^.prev=nil
then GetGlobalPrev:=link^.prnt
else if link^.prev^.tail=nil
then GetGlobalPrev:=link^.prev
else begin
search:=link^.prev^.tail;
while search^.tail<>nil do search:=search^.tail;
GetGlobalPrev:=search;
end;
end;
function aLink.MakeTop(child:pLink):boolean;
begin
MakeTop:=false;
if Del(child)<>true then exit;
if Add(child)<>true then exit;
MakeTop:=true;
end;
function aLink.MakeBot(child:pLink):boolean;
begin
MakeBot:=false;
if Del(child)<>true then exit;
if Ins(nil,child)<>true then exit;
MakeBot:=true;
end;
destructor aLink.Destroy;
begin
end;
end.